﻿using System;

namespace BSU.CSCE.Utilities
{
    public static class StringExtensions
    {
        public static string EmptyToNull(this string source)
        {
            return source == String.Empty ? null : source;
        }

        public static string NullToEmpty(this string source)
        {
            return source ?? String.Empty;
        }

        public static DateTime? ToNullableDate(this string source)
        {
            DateTime tempDate;
            DateTime? dateParam = null;

            if (DateTime.TryParse(source, out tempDate))
            {
                dateParam = tempDate;
            }

            return dateParam;
        }
    }
}
